package com.xiaotao.commons.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel("common-result")
public class R<T> implements Serializable {
    @ApiModelProperty(value = "返回信息")
    private String message;

    @ApiModelProperty(value = "返回状态码")
    private Integer code;

    @ApiModelProperty(value = "返回实体信息")
    private T data;

    public static<T> R<T> success(String message, T data){
        return common(message,200,data);
    }

    public static<T> R<T> success(T data){
        return success("success",data);
    }

    public static<T> R<T> fail(String message, T data){
        return common(message,400,data);
    }

    public static<T> R<T> fail(T data){
        return fail("error",data);
    }

    public static<T> R<T> common(String message, Integer code, T data){
        return new R<T>(message,code,data);
    }

    public R(String message, Integer code, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }
}
